package com.example.front.controller;

import com.example.common.dto.JsonResult;
import com.example.common.dto.ListDto;
import com.example.common.dto.Pagination;
import com.example.front.dto.BoxCreateDto;
import com.example.front.dto.BoxDto;
import com.example.front.dto.BoxSearchDto;
import com.example.front.dto.MaintenanceDto;
import com.example.front.entity.Equipment;
import com.example.front.entity.Maintenance;
import com.example.front.mapper.MaintenanceMapper;
import com.example.front.serivce.MaintenanceService;
import com.example.interceptor.UserContext;
import com.example.passport.entity.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

@Api(tags = "维修班组")
@CrossOrigin
@RestController
@RequestMapping("/front/maintenance")
public class MaintenanceController {

    @Resource
    MaintenanceService maintenanceService;

//    @ApiOperation("添加维修班组")
//    @PostMapping("/create")
//    public JsonResult<String> create(@Valid Equipment equipment) {
//        equipmentService.createEquipment(equipment);
//        return new JsonResult<>(true, "添加成功");
//    }

    @ApiOperation("列出维修班组")
    @GetMapping("/list")
    public JsonResult<ListDto<Maintenance>> list(@Valid Maintenance condition, Pagination pagination) {
        User user= UserContext.getUser();
        condition.setTenantId(UserContext.getUser().getTenantId());
        ListDto<Maintenance> list = maintenanceService.list(condition, pagination);
        return new JsonResult<>(list);
    }

    @ApiOperation("修改数据")
    @PostMapping("/update")
    public JsonResult<String> update(@Valid MaintenanceDto maintenanceDto) {
        maintenanceService.update(maintenanceDto);
        return new JsonResult<>();
    }

    @ApiOperation("删除设备")
    @PostMapping("/deletion")
    public JsonResult<String> deletion(long id) {
        maintenanceService.deletion(id);
        return new JsonResult<>();
    }

    @ApiOperation("列出盒子类型")
    @GetMapping("/findById")
    public JsonResult<Maintenance> findById(Maintenance condition, Pagination pagination) {

        Maintenance maintenance = maintenanceService.findById(condition.getId());

        return new JsonResult(maintenance);
    }
    @ApiOperation("添加班组")
    @PostMapping("/create")
    public JsonResult<String> create(@Valid MaintenanceDto maintenanceDto) {
        maintenanceService.create(maintenanceDto);
        return new JsonResult<>();
    }

}
